package com.szxx.domain;

import com.szxx.constant.GdyCardConstant;
import com.szxx.suit.GdyTypeUtil;

/**
 * 牌 <br>
 *
 * @author Ambrose
 */
public class GdyCard extends LaiziCard {

	public GdyCard() {
	}

	public GdyCard(CardShape cardShape, int number) {
		super(cardShape, number);
	}

	public GdyCard(CardShape cardShape, int number, boolean isLazi) {
		super(cardShape, number, isLazi);
	}

	public GdyCard(CardShape cardShape, int number, boolean isLazi, int laiziType) {
		super(cardShape, number, isLazi, laiziType);
	}

	@Override
	public Card revalue() {
		if (isLazi() && getLaziNumber() != 0) { // 有癞子点数的时候重新定义value
			if (getLaziNumber() == 1) {
				setValue(GdyCardConstant.NUMBER_1_VALUE);
			} else if (getLaziNumber() == 2) {
				setValue(GdyCardConstant.NUMBER_2_VALUE);
			} else {
				setValue(getLaziNumber());
			}
			return this;
		} else {
			if (getCardShape() == CardShape.RED_JOKER) { // 大王
				setNumber(GdyCardConstant.RED_JOKER_SHAPE_NUM);
				setValue(GdyCardConstant.RED_JOKER_SHAPE_VALUE);
			} else if (getCardShape() == CardShape.BLACK_JOKER) { // 小王
				setNumber(GdyCardConstant.BLACK_JOKER_SHAPE_NUM);
				setValue(GdyCardConstant.BLACK_JOKER_SHAPE_VALUE);
			} else {
				if (getNumber() == 1) {
					setValue(GdyCardConstant.NUMBER_1_VALUE);
				} else if (getNumber() == 2) {
					setValue(GdyCardConstant.NUMBER_2_VALUE);
				} else {
					setValue(getNumber());
				}
			}
			return this;
		}
	}

	/**
	 * 创建实例
	 * 
	 * @return
	 */
	@Override
	protected Card newInstance() {
		return new GdyCard(getCardShape(), getNumber(), isLazi(), getLaiziType());
	}

	/**
	 * 改变癞子牌
	 * 
	 * @param laziNumber
	 */
	@Override
	public void doChangeCard(int valueOrNumber) { // 有癞子点数的时候重新定义value
		setLaziNumber(GdyTypeUtil.getNumberByValue(valueOrNumber));
	}
	
	@Override
	public boolean isLazi() {
		return getCardShape() == CardShape.BLACK_JOKER 
				|| getCardShape() == CardShape.RED_JOKER;
	}

}
